<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>严重异动提醒</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">									
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}
			table{
				margin:-5px 0px 0px 0px;
				width:600px; 
				border-collapse:collapse; 
				text-align:center;
			}
			td,th{border:1px solid #696969}					
		</style>
	</head>
	<body>							
		<div id="towrite" class="fixedBox"></div>			
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>		
		<script>
			var bkcolor = $("body").css("backgroundColor")					
			var tdx = 1; 
			window.onload = function() {
				if(navigator.userAgent.indexOf("TdxW") == -1){ //识别是否为通达信
					tdx = 0;
				}
				getSource();			
				changeStyle();					
			}
			
			function changeStyle() {
				var obj = document.getElementById("towrite");				
				obj.style.left= "0px"; 				
				obj.style.width= "98%";	
				obj.style.height= "98%";		
				obj.style.fontSize="14px";			
			}								
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {					
					getSource();					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
					time_range("9:00","15:15")	
				},
				60000);
			})
			
			function getSource() {
				var div = document.getElementById('towrite');	
				div.innerHTML = "<p style='color:#FFFF88;font-size:16px'>严重异动提醒</p>";				
				var url1 = "https://apphq.longhuvip.com/w1/api/index.php?a=GetPianLiZhi_Index&apiv=w34&c=StockBidYiDong";
				var res1 = [];
				$.ajax({
					type: "get",
					url: url1,						
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {					
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));	
						res1 = data.List;
					}
				});	
				
				var arr1 = [];
				for (var i = 0; i < res1.length; i++){
					var aa = res1[i];
					var t = "";
					if(aa[2] == 0){
						t = "当日";
					}else if(aa[2] == 1){
						t = "次日";
					}
					var zf = aa[4];
					var ydzf = aa[8];
					var y = "否";
					if(zf >= ydzf){
						y = "是";
					}
					arr1.push({"代码":aa[0],"名称":aa[1],"涨幅":zf,"何日":t,"几日":aa[5],"偏离值":aa[6],"异动价格":aa[11],"异动涨幅":ydzf,"详情":aa[7],"触发":y})
				}
				//document.write(JSON.stringify(arr));	
				
				if(arr1.length > 0){
					tables(arr1,"严重异动提醒");											
				}else{
					div.innerHTML += "<p style='margin-top:-10px;'>暂无数据</p>";
				}
				
				div.innerHTML += "<p style='color:#FFFF88;font-size:16px'>重点监控股票</p>";				
				var url2 = "https://apphq.longhuvip.com/w1/api/index.php?a=GetYDTP_ZDJK_Today&apiv=w34&c=StockBidYiDong";
				var res2 = [];
				$.ajax({
					type: "get",
					url: url2,						
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {					
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));	
						res2 = data.List;
					}
				});	
				
				var arr2 = [];
				for (var i = 0; i < res2.length; i++){
					var aa = res2[i];
					var lb = "";
					if(aa[4] == 1){
						lb = "";
					}else if(aa[4] == 2){
						lb = "动态发布";
					}else if(aa[4] == 3){
						lb = "重点监控";
					}
					arr2.push({"代码":aa[0],"名称":aa[1],"开始":aa[2],"结束":aa[3],"类别":lb})
				}
				//document.write(JSON.stringify(arr));	
				
				if(arr2.length > 0){
					tables(arr2,"重点监控股票");											
				}else{
					div.innerHTML += "<p style='margin-top:-10px;'>暂无数据</p>";
				}
				
				div.innerHTML += "<p style='color:#FFFF88;font-size:16px'>多次异动个股</p>";			
				var url3 = "https://apphq.longhuvip.com/w1/api/index.php?a=GetPianLiZhi_Many&apiv=w34&c=StockBidYiDong";
				var res3 = [];
				$.ajax({
					type: "get",
					url: url3,						
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {					
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));	
						res3 = data.List;
					}
				});	
				
				var arr3 = [];
				for (var i = 0; i < res3.length; i++){
					var aa = res3[i];
					if(aa[4] < 4){
						var cs = aa[3].replace("当前10日内","").replace("次异动个股","");
						arr3.push({"代码":aa[0],"名称":aa[1],"现价":aa[9],"涨幅":aa[10],"异动日期":aa[5],"预计触发价格":aa[7],"触发涨幅":aa[8],"3日偏离值":aa[6],"次数":cs})
					}
				}
				//document.write(JSON.stringify(arr));	
				function up(a,b){
					return b.次数 - a.次数											
				}
				arr3.sort(up);
				
				if(arr3.length > 0){
					tables(arr3,"多次异动个股");											
				}else{
					div.innerHTML += "<p style='margin-top:-10px;'>暂无数据</p>";
				}
			}
			
			function tables(data,id) {
				var json = data;
				
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
											
				for(var key in json[0]){  //表头
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);
					if(key == "偏离值" || key == "异动价格" || key == "异动涨幅" || key == "详情" || key == "触发" || key == "类别" || key == "预计触发价格" || key == "触发涨幅"){
						th.id = "BJ";
						th.style.color = "#FFA500";	
					}						
				}

				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;
					var dm = "";
					var mc = "";
					for(var key in json[i]){ //行元素遍历						
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
							tr.id = id + "#" + dm;
						}else if(p == 2){
							mc = rc;
						}
						
						var href = "http://www.treeid/code_" + dm;							
						if(tdx == 0){
							href = "javascript:void(0);";	
						}
						td.innerHTML = "<a href=" + href + " id='" + p + "' onclick='changeCss(\"" + tr.id + "\")'>" + rc + "</a>";
						//td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='lhb(\"" + dm + "\",\"日期\");changeCss(\"" + tr.id + "\",\"" + ids + "\")'>" + rc + "</a>";
						
						var th=table.getElementsByTagName("th");
						if(th[p-1].id=="BJ"){
							//td.getElementsByTagName("a")[0].id = "BJ" + p;
							td.getElementsByTagName("a")[0].style.color = "#FFA500";
							var ss = td.getElementsByTagName("a")[0].text;
							if(ss == "重点监控" || ss == "是"){
								td.getElementsByTagName("a")[0].style.color = "#80FF00";
							}				
						}
						
						tr.appendChild(td);													
						p++;
					}
					tbody.appendChild(tr);																
				}
				
				var div = document.getElementById("towrite");												
				div.appendChild(table);
				//table.id = "table" + id;	
				<!-- if(fs > 1){ -->
					<!-- changeTable(table,"0") -->
				<!-- } -->
				hover();
			}
			
			var temp = "";	
			function update(ss) {	
				div = document.getElementById(ss);
				if(temp.indexOf(ss) == -1){
					temp += ss + ";";
					div.style.display = "block";
				}else{
					temp = temp.replace(ss + ";" , "");
					div.style.display = "none";
				}
			}
			
			var trid = "";
			function changeCss(hid){
				var tlist = document.getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor;			
				}
				trid = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hover(){ 
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头														
							this.style.background = bkcolor;
							if(this.id == trid){									
								this.style.background="#483D8B";
							}							
						}
					}					
				}
			}
		</script>						
	</body>
</html>